import $axios from "@/network";

/**
 * {组织机构添加，编辑共用参数}
 *
 * @author: 宋康
 * @date: 2022/8/17 15:15
 */
export const orgPublic = {
  data() {
    return {
      form: {
        orgName: '',
        orgCode: '',
        parentId: '0',
        orgSite: '',
        des: ''
      },
      rules: {
        orgName: [
          {required: true, message: '请输入组织名称', trigger: 'blur'},
          {min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur'}
        ],
        orgCode: [
          {min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur'}
        ],
        orgSite: [
          {min: 1, max: 1000, message: '长度在 1 到 1000 个字符', trigger: 'blur'}
        ],
        des: [
          {min: 1, max: 1000, message: '长度在 1 到 1000 个字符', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    /**
     * {返回}
     *
     * @author: 宋康
     * @date: 2022/8/17 10:16
     */
    cancel() {
      this.$router.go(-1)
    },
  }
}
/**
 * {查询组织机构列表(分页)}
 * @param current
 * @param size
 * @param keyword
 * @author: 宋康
 * @date: 2022/8/17 15:15
 */
export const orgPage = (current, size, keyword) => {
  return $axios({
    method: 'POST',
    url: '/org/query/page',
    params: {
      current,
      size,
    },
    data: {
      keyword:keyword,
      isParent: true
    }
  })
}

/**
 * {查询组织机构列表}
 * @param keyword
 * @param isParent
 * @param excludes
 * @author: 宋康
 * @date: 2022/8/17 15:25
 */
export const orgList = (keyword, isParent, excludes) => {
  return $axios({
    method: 'POST',
    url: '/org/query/list',
    data: {
      keyword,
      isParent,
      excludes
    }
  })
}

/**
 * {查询指定组织}
 *
 * @param oid
 * @author: 宋康
 * @date: 2022/8/17 14:37
 */
export const queryOrgByOid = (oid) => {
  return $axios({
    url: '/org/query',
    params: {
      oid
    }
  })
}

/**
 * {保存组织机构}
 * @param option
 * @author: 宋康
 * @date: 2022/8/17 11:29
 */
export const saveOrg = (option) => {
  return $axios({
    method: 'POST',
    url: '/org/save',
    data: {
      ...option
    }
  })
}

/**
 * {编辑组织机构}
 * @param option
 * @author: 宋康
 * @date: 2022/8/17 15:10
 */
export const editOrg = (option) => {
  return $axios({
    method: 'POST',
    url: '/org/edit',
    data: {
      ...option
    }
  })
}

/**
 * {移除指定组织机构}
 * @param oid
 * @author: 宋康
 * @date: 2022/8/17 15:52
 */
export const removeOrg = (oid) => {
  return $axios({
    method: 'POST',
    url: '/org/remove',
    params: {
      oid
    }
  })
}